W6: Embedded programming

We arrive to week #6 of Fablab Academy and this week is all about embedded programming. In this week I won't be using any machine like I did last week, but I have a some assignments to complete. So let´s begin with this week journey and see how everything works out for me.

This week assignmets are:

Group assignments:

Individual assignments:

What will I need for this week assignments:


Embedded system structure

What is embedded programming?

Embedded systems programming, also known as embedded programming, facilitates the development of consumer-facing devices that don't use conventional operating systems the way that desktop computers and mobile devices do. Microprocessors and microcontrollers are built into these embedded devices to aid in the performance of a single function or set of related functions. Common examples of embedded systems include microwaves, smart refrigerators, industrial robots, video consoles and satellites.

Many embedded systems might not have a user interface (UI) if they are programmed to carry out a specific task inside a device such as the computers that control an automobile's tire pressure monitoring system or antilock brake system. Due to the lack of a human interface, these embedded systems use sensors to monitor specific features and can initiate an automated action in response to data received from the sensor. Yet, other embedded systems, such as those seen in mobile devices, will have intricate graphical UIs using a touchscreen, LED and button technologies.


Data from: embedded programming


Arduino Software IDE

Using Arduino Software (IDE)

The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them.

Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The Arduino Arduino Software (IDE) - connects to the Arduino boards to upload programs and communicate with them. These sketches are written in the text editor and are saved with the file extension .ino.

Libraries

Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. To use a library in a sketch, select it from the Sketch > Import Library menu. This will insert one or more #include statements at the top of the sketch and compile the library with your sketch. Because libraries are uploaded to the board with your sketch, they increase the amount of space it takes up. Some libraries are included with the Arduino software. Others can be downloaded from a variety of sources or through the Library Manager.

Data from: IDE






Protoboard

Protoboard / breadboard

The Protoboard, also known as a breadboard, solderless breadboard, or terminal array board, is a type of building platform used to create semi-permanent prototypes of electronic circuits without soldering.

Is simply a board for prototyping or building circuits on. It allows you to place components and connections on the board to make circuits without soldering. The holes in the breadboard take care of your connections by physically holding onto parts or wires where you put them and electrically connecting them inside the board. The ease of use and speed are great for learning and quick prototyping of simple circuits. Breadboard circuits are also not ideal for long term use like circuits built on perfboard or PCB, but they also don’t have the soldering, or design and manufacturing costs (PCBs).

Why do you use a BreadBoard?

A breadboard is handy because you can set up circuits quickly and temporarily to test them and move on to a more permanent arrangement after investigating how it works on the breadboard. They are great for hobbyists and tinkerers to set up projects as a standalone device or as a peripheral to an Arduino, Raspberry Pi, LaunchPad, BeagleBone, and many other development boards. They come in many sizes to fit projects large and small. Breadboards are also inexpensive, and the parts that work with them are also typically inexpensive too.

Data from: Protoboard


Group Assignments


1. XIAO-ESP32-S3

Seeed Studio XIAO is a thumb-sized development board. “XIAO” means tiny, tiny but powerful. All XIAO development boards are empowered by powerful and popular chips, such as SAMD21, nRF52840, and ESP32C3, it is possible for a wide range of applications. In addition, it is compact and all SMD components are placed on the same side of the board, so designers can easily integrate XIAO into their own boards for rapid mass production.

Seeed Studio XIAO Series are diminutive development boards, sharing a similar hardware structure, where the size is literally thumb-sized. The code name "XIAO" here represents its half feature "Tiny", and the other half will be "Puissant". Seeed Studio XIAO ESP32S3 Sense integrates camera sensor, digital microphone and SD card supporting. Combining embedded ML computing power and photography capability, this development board can be your great tool to get started with intelligent voice and vision AI.

Characteristics:
High-performance: Incorporate the ESP32S3 32-bit, dual-core, Xtensa processor chip operating up to 240 MHz, mounted multiple development ports, Arduino / MicroPython supported
Ultra low-power: Detachable OV2640 camera sensor for 1600*1200 resolution, compatible with OV5640 camera sensor, intergating additional digital microphone
Wireless: Lithium battery charge management capability, offer 4 power consumption model which allows for deep sleep mode with power consumption as low as 14μA
Iot breakthroughs: Offer 8MB PSRAM and 8MB FLASH, supporting SD card slot for external 32GB FAT memory
Features:
Powerful MCU Board: Incorporate the ESP32S3 32-bit, dual-core, Xtensa processor chip operating up to 240 MHz, mounted multiple development ports, Arduino / MicroPython supported
Advanced Functionality (for Sense): Detachable OV2640 camera sensor for 1600*1200 resolution, compatible with OV5640 camera sensor, intergating additional digital microphone
Elaborate Power Design: Lithium battery charge management capability, offer 4 power consumption model which allows for deep sleep mode with power consumption as low as 14μA
Great Memory for more Possibilities: Offer 8MB PSRAM and 8MB FLASH, supporting SD card slot for external 32GB FAT memory
Outstanding RF performance: Support 2.4GHz Wi-Fi and BLE dual wireless communication, support 100m+ remote communication when connected with U.FL antenna
Thumb-sized Compact Design: 21 x 17.5mm, adopting the classic form factor of XIAO, suitable for space limited projects like wearable devices

Data from: ESP32S3 and

Data from: SEEED Studio

A). Applications

With low power consumption, ESP32-S3 is an ideal choice for IoT devices in the following areas:

  • Smart Home
  • Industrial Automation
  • Health Care
  • Consumer Electronics
  • Smart Agriculture
  • POS machines
  • Service robot
  • Audio Devices
  • Generic Low-power IoT Sensor Hubs
  • Generic Low-power IoT Data Loggers
  • Cameras for Video Streaming
  • USB Devices
  • Speech Recognition
  • Image Recognition
  • Wi-Fi + Bluetooth Networking Card
  • Touch and Proximity Sensing

B). Pin Overview

The ESP32-S3 chip integrates multiple peripherals that require communication with the outside world. To keep the chip package size reasonably small, the number of available pins has to be limited. So the only way to route all the incoming and outgoing signals is through pin multiplexing. Pin muxing is controlled via software programmable registers

All in all, the ESP32-S3 chip has the following types of pins:

Types of pins:
IO pins with the following predefined sets of functions to choose from: Each IO pin has predefined IO MUX and GPIO functions
Some IO pins have predefined RTC functions
Some IO pins have predefined analog functions

Predefined functions means that each IO pin has a set of direct connections to certain on-chip components. During run-time, the user can configure which component from a predefined set to connect to a certain pin at a certain time via memory mapped registers

Data from: DataSheet

C). Hardware Overview

It is quite essential to have some basic parameters of the product. The following table provides information about the characteristics of Seeed Studio XIAO ESP32S3.


At each startup or reset, a chip requires some initial configuration parameters, such as in which boot mode to load the chip, voltage of flash memory, etc. These parameters are passed over via the strapping pins. After reset, the strapping pins operate as regular IO pins. The parameters controlled by the given strapping pins at chip reset are as follows:

Data from: DataSheet

D). Technical Specifications Seeed Studio XIAO ESP32S3

Processor:
  • Xtensa LX7 dual-core, 32-bit processor that operates at up to 240 MHz
  • Wireless:
  • Complete 2.4GHz Wi-Fi subsystem
  • BLE: Bluetooth 5.0, Bluetooth mesh
  • Built-in Sensors:
  • -
  • Memory:
  • On-chip 8M PSRAM & 8MB Flash
  • Interface:
  • 1x UART, 1x IIC, 1x IIS, 1x SPI, 11x GPIOs (PWM), 9x ADC, 1x User LED, 1x Charge LED
  • 1x Reset button, 1x Boot button
  • Dimensions:
  • 21 x 17.5mm
  • Power:
  • Input voltage (Type-C): 5V
  • Input voltage (BAT): 4.2V
  • Charging battery current: 100mA

  • Circuit operating Voltage (ready to operate):
  • Type-C: 5V@19mA
  • BAT: 3.8V@22mA
  • Low Power Consumption Model:
  • Modem-sleep Model: 3.8V/25 mA
  • Light-sleep Model: 3.8V/2 mA
  • Deep Sleep Model: 3.8V/14 μA
  • Wi-Fi Enabled Power Consumption:
  • Active Model: ~ 100 mA
  • BLE Enabled Power Consumption:
  • Active Model: ~ 85 mA
  • Working Temperature:
  • -40°C ~ 65°C
  • Data from: Seeed studio


    2. Arduino

    Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. The Arduino software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux. It it to build low cost scientific instruments, to prove chemistry and physics principles, or to get started with programming and robotics.

    "Uno" means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0. The Arduino Uno R3 Compatible Board is a microcontroller board which is based on the ATmega328. Arduino Uno has 14 digital input or output pins (where 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.

    Features:
    Easy application programming using open source IDE.
    Easy to learn Microcontroller using Arduino boards.
    Easy application programming using open source IDE
    Ready Library for most of the sensors and application modules.

    Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems:

    Advantages:
    Inexpensive: Arduino boards are relatively inexpensive compared to other microcontroller platforms.
    Cross-platform: The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows.
    Simple, clear programming environment: The Arduino Software (IDE) is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well.
    Open source and extensible software: The Arduino software is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based.
    Open source and extensible hardware: The plans of the Arduino boards are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it.

    Data from: Arduino

    A). Anatomy of an Arduino Board

    Arduino Uno is an open-source microcontroller board based on the processor ATmega328P. It has digital I/O pins, analog inputs, USB connection, a power jack, an ICSP header, and a reset button. It contains all the necessary modules needed to support the microcontroller.

    Structure:
    Microcontroller: this is the brain of an Arduino, and is the component that we load programs into. Think of it as a tiny computer, designed to execute only a specific number of things.
    USB port: Used to connect your Arduino board to a computer.
    USB to Serial chip: It helps translating data that comes from e.g. a computer to the on-board microcontroller. This is what makes it possible to program the Arduino board from your computer.
    Digital pins: Pins that use digital logic (0,1 or LOW/HIGH). Commonly used for switches and to turn on/off an LED.
    Analog pins: Pins that can read analog values in a 10 bit resolution (0-1023).
    5V / 3.3V pins: These pins are used to power external components.
    GND: also known as ground, negative or simply -, is used to complete a circuit, where the electrical level is at 0 volt.
    VIN: Stands for Voltage In, where you can connect external power supplies.

    Data from: Getting Started with Arduino

    B). Basic Operation

    Most Arduino boards are designed to have a single program running on the microcontroller. This program can be designed to perform one single action, such as blinking an LED. It can also be designed to execute hundreds of actions in a cycle. The scope varies from one program to another.

    The program that is loaded to the microcontroller will start execution as soon as it is powered. Every program has a function called "loop". Inside the loop function, you can for example:

    Loop function:
    Read a sensor.
    Turn on a light.
    Check whether a condition is met.
    All of the above.

    The speed of a program is incredibly fast, unless we tell it to slow down. It depends on the size of the program and how long it takes for the microcontroller to execute it, but it is generally in microseconds (one millionth of a second).

    C). Features

    Processor:
  • ATMega328P
  • Memory:
  • AVR CPU at up to 16 MHz
  • 32KB Flash
  • 2KB SRAM
  • 1KB EEPROM
  • Security:
  • Power On Reset (POR)
  • Brown Out Detection (BOD)
  • Peripherals:
  • 2x 8-bit Timer/Counter with a dedicated period register and compare channels
  • 1x 16-bit Timer/Counter with a dedicated period register, input capture and compare channels
  • 1x USART with fractional baud rate generator and start-of-frame detection
  • 1x controller/peripheral Serial Peripheral Interface (SPI)
  • 1x Dual mode controller/peripheral I2C
  • 1x Analog Comparator (AC) with a scalable reference input
  • Watchdog Timer with separate on-chip oscillator
  • Six PWM channels
  • Interrupt and wake-up on pin change
  • ATMega16U2 Processor:
  • 8-bit AVR® RISC-based microcontroller)
  • Memory:
  • 16 KB ISP Flash
  • 512B EEPROM
  • 512B SRAM
  • 1debugWIRE interface for on-chip debugging and programming
  • Power:
  • 2.7-5.5 volts
  • Data from: Arduino Datasheet

    D). Arduino Pin Layout

    E). Technical Specifications Arduino

    Technical Specifications:
    Microcontroller: ATmega328P
    Operating Voltage: 5V.
    Input Voltage (recommended): 7-12V
    Input Voltage (limit): 6-20V.
    Digital I/O Pins: 14 (of which 6 provide PWM output)
    PWM Digital I/O Pins: 6.
    Analog Input Pins: 6.
    DC Current per I/O Pin: 20 mA.
    DC Current for 3.3V Pin: 50 mA.
    Flash Memory: 32 KB (ATmega328P) of which 0.5 KB used by bootloader.
    SRAM: 2 KB (ATmega328P).
    EEPROM: 1 KB (ATmega328P).
    Clock Speed: 16 MHz.
    LED_BUILTIN: 13.
    Length: 68.6 mm.
    Width: 53.4 mm.
    Weight: 25 g.

    Data from: Arduino CC


    3. XIAO-ESP32-S3 vs Arduino Uno

    In this section i'll make a comparison between the XIAO-ESP32-S3 and the Arduino UNO. I'm going to focus in what I think are both microcontroller features. At this moment I haven't had the opportunity to work with any of the microcontrollers so this is base on what I have investigate.

    XIAO-ESP32-S3

    ESP32 has various interfaces for peripherals, like Wi-Fi and Bluetooth, allowing connectivity. It has numerous GPIO pins and communication interfaces.

    It supports various programming languages like C, C++, and Python.

    Based on the technical specifications, I think this one is used in advanced projects with higher/powerful processing capabilities.

    It may be one the most popular microcontrollers for more advanced and experienced users due to its wifi and bluetooth connectivity.

    Arduino UNO

    It has become one of the most popular microcontroller due to its ease use. It has several GPIOs and common microcontroller communication interfaces.

    Although it has a lower processing power compared to ESP32 it can be use for smaller and simpler projects.

    As XIAO-ESP32-S3, Arduino supports C, C++ and microPython and counts with many libraries.

    Based on the features that Arduino offers, it can be used for small and simple projects with lower processing requierements, maybe it's the best option for someone who has just begun in electronics.



    Individual Assignments


    Before programming the microcontroller I have to connect the board / arduino to my pc, not at the same time.

    A). Programming a microcontroller with ESP32

    A1). Blinking led

    Now i'm going to use the XIAO-ESP32, in this part i'm testing:

    Once I have connect the board to my laptop, I follow the next steps:



    Here's a short video of the test:


    A2). Led on/off with button

    For this second code, im going to use a button to control de LED. The idea is to turn ON/OFF the LED once I press the button. Lets begin with this code and see how well it goes:

    I'll explain the code that is shown in the image below:

    Here's the video showing the result of the code:

    A3). Led on/off introducing text from PC

    For the third code, im using my PC to turn on/off the led. The idea is to turn ON/OFF the LED when I type the word "On" or "Off". Lets take a look to the code:

    I'll explain the code that is shown in the image below:

    Code from: ESP32 - Serial Input/Output

    Here's the video for this third example:


    B). Programming with Arduino UNO

    Now for this part I'm using the same examples I use with ESP32 but with Arduino. So lets begin and see how different they are.

    Components for the first code, Blinking led, I need to use:

    B1). Arduino blinking led

    This is the first code with arduino. What it does it makes the led blink and you can indicate the blinking time. Code in section B1 is very similar with the code in section A1, I just have to declare the pins where I connect the led.

    The image below shows the code of the Arduino blinking led and the simulation in TinkerCad. So let's explain it:


    B2). Arduino Led on/off with button

    Lets start with the second code with arduino. In this one i'm using a button to turn ON/OFF the led.

    Components for the first code, Blinking led, I need to use:

    In the images below you can see the code of the Arduino Led on/off with button and the simulation in TinkerCad. So let's explain it:


    B3). Led on/off introducing text from PC

    Lets start with the last code with arduino. AS I did in the third example with ESP32, i'm turning ON/OFF the led with the words ON/OFF.

    In the images below you'll see the code in arduino IDE and TinkerCad. Code doesn't change a lot if we compare it to the code in ESP32, sol let's explain it:



    C). Final comments between ESP32 and Arduino UNO

    After I had some experience coding in ESP32 and Arduino ONE and from a very personal point of view I like both of them and can conclude that:


    Final part


    Files

    In this part you can download the files that I use for this 6th week assignments.


    Conclusions and recomendations

    What did I learn in this week?